package com.ruoyi.common.core.utils;

import java.util.*;
import java.util.stream.Collectors;

public class RandomUtils {
    /**
     * 生成指定范围内的随机数
     * @param min 最小值
     * @param max 最大值
     */
    public static Integer random(Integer min, Integer max)
    {
        Random random = new Random();
        int i = random.nextInt(++max);
        if(i <= min){
            i += min;
        }
        return i;
    }

    /**
     * A-Z 0-9
     * @return String
     */
    public static String aAndZ0And9(Integer quantity)
    {
        String[] number = new String[]{"1","2","3","4","5","6","7","8","9","0"};
        String[] str = new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        List<String> strings = new ArrayList<>();
        strings.addAll(Arrays.asList(number));
        strings.addAll(Arrays.asList(str));
        strings.addAll(Arrays.stream(str).map(String::toLowerCase).collect(Collectors.toList()));
        Collections.shuffle(strings);
        StringBuilder result = new StringBuilder();
        for (String s : strings.subList(0, quantity)) {
            result.append(s);
        }
        return result.toString();
    }

    /**
     * 0-9
     * @return String
     */
    public static String randAnd0_9(Integer quantity)
    {
        String[] number = new String[]{"1","2","3","4","5","6","7","8","9","0"};
        List<String> strings = Arrays.asList(number);
        Collections.shuffle(strings);
        StringBuilder result = new StringBuilder();
        for (String s : strings.subList(0, quantity)) {
            result.append(s);
        }
        return result.toString();
    }

    /**
     * A-Z 0-9
     * @return String
     */
    public static String aAndZ(Integer quantity)
    {
        String[] str = new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        List<String> strings = new ArrayList<>();
        strings.addAll(Arrays.asList(str));
        strings.addAll(Arrays.stream(str).map(String::toLowerCase).collect(Collectors.toList()));
        Collections.shuffle(strings);
        StringBuilder result = new StringBuilder();
        for (String s : strings.subList(0, quantity)) {
            result.append(s);
        }
        return result.toString();
    }
}
